package com.ly.hotel.spainterface.pp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.spainterface.pp.bean.PreJSDataBean;
import com.ly.hotel.util.ImageUtil;

import java.util.List;

/**
 * Created by mo on 2018/6/4.
 */

public class PpJSListAdapter extends BaseAdapter {

    private Context context;
    private List<PreJSDataBean> preJSDataBeans;
    private int rod = 0;

    public PpJSListAdapter(Context context, List<PreJSDataBean> preJSDataBeans) {
        this.context = context;
        this.preJSDataBeans = preJSDataBeans;
        rod = context.getResources().getDimensionPixelSize(R.dimen.px6);
    }

    @Override
    public int getCount() {
        return preJSDataBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return preJSDataBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        ViewHolder viewHolder = null;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.pp_gridview_technician_item, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.technicianImage = view.findViewById(R.id.technician_image);
            viewHolder.technicianNum = view.findViewById(R.id.technician_num);
            viewHolder.technicianStatus = view.findViewById(R.id.technician_status);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        PreJSDataBean preJSDataBean = preJSDataBeans.get(position);
        String imageUrl = MyApplication.getHostResUrl() + "/upload/" + preJSDataBean.getImg();
        ImageUtil.displayImage_Round(context, imageUrl, viewHolder.technicianImage, rod);
        viewHolder.technicianNum.setText(preJSDataBean.getNo());
        viewHolder.technicianStatus.setText(preJSDataBean.getName());
        return view;
    }

    class ViewHolder {
        ImageView technicianImage;
        TextView technicianNum;
        TextView technicianStatus;
    }
}
